<template>
  <div
    class="m-window applyLong-col"
    style="overflow: auto; overflow-x: hidden;"
    v-loading="pageLoading"
    element-loading-text="数据加载中"
  >
    <!--金融审批长融提交申请表-->
    <el-row :gutter="10" class="header-btns-col">
      <el-col :span="2">
        <el-button type="primary" @click="backtrack">返回</el-button>
      </el-col>
    </el-row>
    <el-row
      :gutter="10"
      style="margin:8px auto;"
      class="footer-btns-col"
      v-show="fromPage == 'myToDoList' && !pageLoading"
    >
      <el-col :span="2">
        <el-button type="primary" @click="sendBack">退回</el-button>
      </el-col>
      <el-col :span="2">
        <el-button type="primary" @click="accept">通过</el-button>
      </el-col>
    </el-row>
    <el-row style="margin-top: 60px;">
      <el-col :span="12">
        <el-tabs v-model="activeName" @tab-click="handleClick">
          <el-tab-pane label="供应商" name="first">
            <el-row class="content">
              <el-col :span="12">
                <table class="emphasis-table">
                  <tr>
                    <th>流程编号：</th>
                    <td class="font-underline hit">{{general.itemNo}}</td>
                  </tr>
                  <tr>
                    <th>供应商名称：</th>
                    <td>{{general.custName}}</td>
                  </tr>
                  <tr>
                    <th>融资产品：</th>
                    <td>月有钱</td>
                  </tr>
                  <tr>
                    <th>授信额度：</th>
                    <td>{{getFormatCreditLine}}</td>
                  </tr>
                  <tr>
                    <th>受理意见：</th>
                    <td>{{general.applyRemark}}</td>
                  </tr>
                  <tr>
                    <th>申请融资金额：</th>
                    <td>{{getFormatApplyAmt}}</td>
                  </tr>
                  <tr>
                    <th>申请融资开始日期：</th>
                    <td>{{general.applyDate}}</td>
                  </tr>
                  <tr>
                    <th>申请融资到期日期：</th>
                    <td>{{general.prepaybackDate}}</td>
                  </tr>
                  <tr>
                    <th>申请融资天数：</th>
                    <td>{{getDayAmount}}</td>
                  </tr>
                  <tr>
                    <th>服务费率（不含税）：</th>
                    <td>{{serviceRate}}</td>
                  </tr>
                  <tr>
                    <th>利率（不含税）：</th>
                    <td>{{showRate}}</td>
                  </tr>
                  <tr>
                    <th>服务费（不含税）：</th>
                    <td>{{getService}}</td>
                  </tr>
                  <tr>
                    <th>利息（不含税）：</th>
                    <td>{{getNumberRate}}</td>
                  </tr>
                  <tr>
                    <th>应还款金额：</th>
                    <td>{{getFormatApplyAmt}}</td>
                  </tr>
                  <tr>
                    <th>申请人：</th>
                    <td>{{general.custUser}}</td>
                  </tr>
                  <tr>
                    <th>申请人手机：</th>
                    <td>{{general.custPhone}}</td>
                  </tr>
                </table>
              </el-col>
            </el-row>
          </el-tab-pane>
          <el-tab-pane label="联塑金融" name="second">
            <el-row class="content">
              <el-col :span="12">
                <table class="emphasis-table">
                  <tr>
                    <th>流程编号：</th>
                    <td class="font-underline hit">{{general.itemNo}}</td>
                  </tr>
                  <tr>
                    <th>供应商名称：</th>
                    <td>{{general.custName}}</td>
                  </tr>
                  <tr>
                    <th>融资产品：</th>
                    <td>月有钱</td>
                  </tr>
                  <tr>
                    <th>授信额度：</th>
                    <td>{{getFormatCreditLine}}</td>
                  </tr>
                  <tr>
                    <th>受理意见：</th>
                    <td>{{general.applyRemark}}</td>
                  </tr>
                  <tr>
                    <th>
                      <div>
                        <span style="color:red">*</span>
                        <span>确认融资金额：</span>
                      </div>
                    </th>
                    <td style="padding:0px;" v-if="fromPage=='myToDoList'">
                      <div class="flexs">
                        <el-input
                          v-model="amount"
                          placeholder="输入金额"
                          :disabled="pageSourceCode == 'myProcessed'"
                          @blur="checkNum"
                          @keyup.native="clearNoNum()"
                        ></el-input>
                        <span>元</span>
                      </div>
                    </td>
                    <td style="padding:0 10px;" v-else>{{amount}} 元</td>
                  </tr>
                  <tr>
                    <th>
                      <div>
                        <span style="color:red">*</span>
                        <span>确认融资开始日期：</span>
                      </div>
                    </th>
                    <td style="padding:0 10px;" v-if="fromPage=='myToDoList'">
                      <el-date-picker
                        v-model="beginTime"
                        type="date"
                        placeholder="选择日期"
                        value-format="yyyy-MM-dd HH:mm:ss"
                        :picker-options="pickerOptionsBegin"
                      ></el-date-picker>
                      <!-- :disabled="pageSourceCode == 'myProcessed'" -->
                    </td>
                    <td style="padding:0 10px;" v-else>{{beginTime}}</td>
                  </tr>
                  <tr>
                    <th>
                      <div>
                        <span style="color:red">*</span>
                        <span>确认融资到期日期：</span>
                      </div>
                    </th>
                    <td style="padding:0 10px;" v-if="fromPage=='myToDoList'">
                      <el-date-picker
                        v-model="endTime"
                        type="date"
                        placeholder="选择日期"
                        value-format="yyyy-MM-dd HH:mm:ss"
                        :picker-options="pickerOptionsEnd"
                      ></el-date-picker>
                      <!-- :disabled="pageSourceCode == 'myProcessed'" -->
                    </td>
                    <td style="padding:0 10px;" v-else>{{endTime}}</td>
                  </tr>
                  <tr>
                    <th>确认融资天数：</th>
                    <td>{{getDayAmountTab2}}</td>
                  </tr>
                  <tr>
                    <th>服务费率（不含税）：</th>
                    <td>{{serviceRate}}</td>
                  </tr>
                  <tr>
                    <th>利率（不含税）：</th>
                    <td>{{showRate}}</td>
                  </tr>
                  <tr>
                    <th>服务费（不含税）：</th>
                    <td>{{getServiceFee}}</td>
                  </tr>
                  <tr>
                    <th>利息（不含税）：</th>
                    <td>{{getRateFee}}</td>
                  </tr>
                  <tr>
                    <th>应还款金额：</th>
                    <td>{{amount}} 元</td>
                  </tr>
                </table>
              </el-col>
            </el-row>
          </el-tab-pane>
        </el-tabs>
      </el-col>
    </el-row>
    <div style="margin-top:655px;margin-bottom: 28px;padding:0 10px;">
      <!-- <el-row>
                <el-col :span="12">
                    <div class="detail-headerd">
                        <label>关联对账函</label> 
                        <div class="opts-col" v-show="pageSourceCode != 'myProcessed'">
                            <a href="javasript:;" class="hit" style="margin-right:18px;" @click="addLetter">添加</a>
                            <a href="javasript:;" class="hit" @click="delLetter">删除</a>
                        </div>                    
                    </div>
                    <div class="m-agTable m-top2 m-bottom" style="height:180px;">
                        <ag-grid-vue class="m-agTableContent ag-theme-balham" 
                            :gridOptions="approvalLongGridOptions" 
                            :columnDefs="columnDefs" 
                            :rowData="approvalrowData" 
                            v-loading="loading"
                            :rowSelected="onRowSelected"
                            >
                        </ag-grid-vue>
                    </div>
                </el-col>
      </el-row>-->
      <!-- <el-row>
                <el-col>
                     <div class="files-col">
                        <a href=""><i class="icon el-icon-back"></i>天进宝审核 2018-12-1.excel</a>
                    </div>
                </el-col>
      </el-row>-->
      <el-row>
        <el-col :span="12">
          <el-form :model="applyLongForm" ref="applyLongForm" class="applyLongForm">
            <el-form-item prop="backReason" style="margin-top:-8px;">
              <label>
                退回原因 &nbsp;
                <i class="el-icon-warning"></i>
              </label>
              <el-input
                type="textarea"
                v-model="applyLongForm.backReason"
                placeholder="填写退回原因"
                :disabled="pageSourceCode == 'myProcessed'"
              />
            </el-form-item>
          </el-form>
        </el-col>
      </el-row>
    </div>
    <!-- <el-dialog title="对账函列表" :visible.sync="assemblyModel">
            <el-row :gutter="10" class="m-condition">
                <el-col :span="10">
                <el-input placeholder="输入对账单号查询"></el-input>
                </el-col>
                <el-col :span="3">
                <el-button type="primary" v-model="searchValue" @input="searchLetter">搜索</el-button>
                </el-col>
            </el-row>
            <el-row>
                <el-col>
                <ag-grid-vue
                    class="m-agTableModel ag-theme-balham"
                    :gridOptions="checkingGridOptions"
                    :columnDefs="checkingColumnDefs"
                    :rowData="checkingRowData"
                    v-loading="checkingLoading"
                ></ag-grid-vue>
                </el-col>
            </el-row>
            <el-row type="flex" justify="center">
                <el-col :span="4">
                <el-button type="primary" style="margin:20px 0;" @click="saveLetter">确认</el-button>
                </el-col>
            </el-row>
    </el-dialog>-->
    <!-- 流程图 -->
  </div>
</template>
<style >
.applyLong-col .el-tabs__content {
  overflow: initial;
}
.applyLong-col .el-tabs__nav-wrap::after {
  width: 0;
}
.applyLong-col .el-tabs__active-bar.is-top {
  left: 8px;
}
.applyLong-col .el-tabs__header {
  margin: 0;
}
.applyLong-col .el-tabs__item {
  padding: 0;
  padding-left: 8px !important;
  padding-right: 8px !important;
  height: 30px;
  line-height: 30px;
}
.applyLong-col .el-tabs__active-bar {
  width: 0 !important;
}
.applyLong-col .el-tabs__item.is-active::after {
  display: block;
  content: " ";
  position: absolute;
  height: 2px;
  width: 25px;
  background-color: #409eff;
  bottom: 0;
  left: 50%;
  margin-left: -12.5px;
}
.applyLong-col .el-tabs__nav-scroll {
  padding-left: 10px;
}
.applyLong-col .el-tabs__content .content {
  margin-top: -22px;
}
.applyLong-col .el-input__inner {
  border: 0px;
  padding: 0 0 0 30px;
}
.flexs {
  display: flex !important;
}
.flexs span {
  padding: 10px 0 !important;
}
</style>

<style  lang="less" rel="stylesheet/less" scoped >
.footer-btns-col,
.header-btns-col {
  position: fixed;
  height: 60px;
  width: 100%;
  bottom: 0;
  z-index: 10;
  margin-left: -11px !important;
  box-sizing: border-box;
  display: flex;
  justify-content: center;
  align-items: center;
  background: #fff;
  padding: 10px 0;
  border-top: 1px solid #eee;
  /deep/ .el-button {
    margin-left: -84px;
  }
}
.header-btns-col {
  top: 0;
  justify-content: flex-start;
  border-top: none;
  border-bottom: 1px solid #eee;
  margin-top: 100px;
  /deep/ .el-button {
    margin-left: 8px;
  }
}
a.hit {
  color: #409eff;
}
.applyLong-col {
  overflow: auto;
  color: #949494;
}
.applyLong-col .detail-table {
  width: 100%;
  border: 1px solid #eee;
}
.applyLong-col .detail-table td,
.applyLong-col .detail-table th {
  border-left: 1px solid #eee;
  text-align: center;
  padding: 10px 0;
}
.applyLong-col .detail-headerd {
  padding: 10px 0;
}
.applyLong-col .detail-headerd .opts-col {
  float: right;
}
.applyLong-col .files-col {
  display: flex;
  flex-direction: row;
  flex-wrap: wrap;
}
.applyLong-col .files-col a {
  display: block;
  width: 250px;
  height: 60px;
  line-height: 60px;
  margin-right: 10px;
  border: 1px solid #eee;
  color: #818181;
  box-sizing: border-box;
  padding-right: 10px;
}
.applyLong-col .files-col i.icon {
  display: inline-table;
  width: 60px;
  text-align: center;
  height: 60px;
  line-height: 60px;
  border-right: 1px solid #eee;
  margin-right: 10px;
}
.emphasis-table {
  width: 100%;
  margin-top: 10px;
  td,
  th {
    border: 1px solid #eee;
    padding: 10px;
    width: 50%;
  }
  & tr:nth-child(even) th,
  & tr:nth-child(even) td {
    background: #f9fafa;
  }
  .font-underline {
    text-decoration: underline;
  }
  .hit {
    color: #409eff !important;
  }
  /deep/.el-input {
    width: 75% !important;
  }
}
.emphasis-table th {
  text-align: right;
}
.emphasis-table td {
  text-align: left;
}
.appL-input {
  border: none !important;
  height: 100%;
  width: 100%;
  padding: 0 15px;
  color: #606266;
  box-sizing: border-box;
}
.appL-input:focus {
  outline: none;
}
</style>

<script>
import gridOptions from "lesso-common/public/gridOptions";
import constant from "@/public/constant";
import { mapState, mapGetters, mapActions } from "vuex";
import {
  numberDiv,
  formatPrice,
  formatPriceEdit,
  regainOriginalMoneyFormat,
  formatRate,
  dateDiff,
  getSpecifyDate,
  numberMul,
  numberSub
} from "@/util/format.js";

export default {
  props: ["pageSourceCode"],
  data() {
    return {
      pageLoading: true,
      whitelist: [],
      blacklist: [],
      activeName: "first",
      applyLongForm: {
        backReason: ""
      },
      applyId: "", //请求所用的id
      // custId:"",   //供应商id
      linkName: "act_fin_long_review",
      examinePass: 3, //处理结果  2是通过，3是退回,0默认

      //页面列表
      loading: false,
      approvalLongGridOptions: {},
      columnDefs: [],
      approvalrowData: [],

      amount: "",
      applyAmt: "",
      beginTime: "",
      endTime: "",
      tabDayAmount: "",
      //列表对象数据
      general: {},

      //弹窗列表
      checkingGridOptions: {},
      checkingColumnDefs: [],
      checkingRowData: [],
      checkingLoading: false,
      assemblyModel: false,

      listArray: [],
      searchValue: "",

      fromPage: ""
    };
  },
  beforeMount() {
    this.applyId = this.supplyChainFinance.role.ID;
    this.fromPage = this.supplierApplyList.fromPage;
    this.approvalLongGridOptions = gridOptions();
    this.checkingGridOptions = gridOptions();
    this.checkingColumnDefs = [
      {
        checkboxSelection: true, //是否显示复选框
        headerCheckboxSelection: true, //是否显示全选框
        headerName: "对账函编号",
        field: "accountCode"
      },
      {
        headerName: "应收",
        field: "payBalance",
        valueFormatter: params => {
          return formatPrice(params.value);
        }
      },
      {
        headerName: "可融金额",
        field: "borrowBalance",
        valueFormatter: params => {
          return formatPrice(params.value);
        }
      },
      {
        headerName: "融资状态",
        field: "finStatus",
        cellRenderer: function(params) {
          if (params.value != undefined && params.value == 1) {
            return "部分融资";
          } else if (params.value == 2) {
            return "已融资";
          } else {
            return "未融资";
          }
        }
      }
    ];
    this.columnDefs = [
      {
        checkboxSelection: true, //是否显示复选框
        headerCheckboxSelection: true, //是否显示全选框
        headerName: "对账函编号",
        field: "accountCode"
      },
      {
        headerName: "应收",
        field: "payBalance",
        valueFormatter: params => {
          return formatPrice(params.value);
        }
      },
      {
        headerName: "可融金额",
        field: "borrowBalance",
        valueFormatter: params => {
          return formatPrice(params.value);
        }
      },
      {
        headerName: "融资状态",
        field: "finStatus",
        cellRenderer: function(params) {
          if (params.value != undefined && params.value == 1) {
            return "部分融资";
          } else if (params.value == 2) {
            return "已融资";
          } else {
            return "未融资";
          }
        }
      }
    ];
    this.getDays();
    this.getApplyInfo();
  },
  methods: {
    ...mapActions([
      "changeMyProcessedCTCode",
      "changePageCode",
      "changeFromPage",
      "changeTOdo"
    ]),
    handleClick(val) {
      console.log(val);
    },
    addReturnMoney() {},
    backtrack() {
      if (this.pageSourceCode == "myProcessed") {
        this.changeMyProcessedCTCode("");
      } else if (this.supplierApplyList.pageCode == "approvalLongCommit") {
        this.changePageCode("");
      } else {
        this.$store.dispatch("changeTOdo", { isMyToDoList: 0 });
      }
    },
    //通过方法
    accept() {
      if (this.amount == "") {
         this.$alert("请填写实际融资金额", {
                    confirmButtonText: "确定",
                    customClass: "alertPrompt"
                });
        return;
      }
      // if (regainOriginalMoneyFormat(this.amount) <= 0) {
      //     this.$message.error("请输入大于0的融资金额，可保留2位小数");
      //     return;
      // }
      if (regainOriginalMoneyFormat(this.amount) < 10000) {
        this.amount = "";
         this.$alert("实际融资金额不得低于一万元", {
                    confirmButtonText: "确定",
                    customClass: "alertPrompt"
                });
        return;
      }
      if (this.beginTime == "" || this.beginTime == null) {
          this.$alert("请选择融资日期", {
              confirmButtonText: "确定",
              customClass: "alertPrompt"
          });
        return;
      }
      if (this.endTime == "" || this.endTime == null) {       
        this.$alert("请选择融资到期时间", {
              confirmButtonText: "确定",
              customClass: "alertPrompt"
          });
        return;
      }
      let applyDay = dateDiff(this.beginTime, this.endTime) - 1
      if (applyDay < 31) {       
        this.$alert("“月有钱”产品最小融资天数为31天，请重新选择融资开始日期或到期日期", {
              confirmButtonText: "确定",
              customClass: "alertPrompt"
          });
        return;
      }
      if (applyDay > 186) {
        this.$alert("“月有钱”产品最大融资天数为186天，请重新选择融资开始日期或到期日期", {
              confirmButtonText: "确定",
              customClass: "alertPrompt"
          });
        return;
      }
      // if(this.approvalrowData.length<=0){
      //     this.$message.error("请添加关联对账函明细");
      //     return;
      // }
      let _this = this;
      this.$confirm("是否确认通过？").then(() => {
        _this.approvedFinL();
      });
    },

    approvedFinL() {
      const loading = this.$loading({
        lock: true,
        text: "处理中，请稍等",
        spinner: "el-icon-loading",
        background: "rgba(255,255,255,.9)"
      });
      let params = {
        actAmt: regainOriginalMoneyFormat(this.amount),
        payDate: this.beginTime,
        id: this.general.id,
        paybackDate: this.endTime,
        updateBy: constant.userId,
        updator: constant.employeeName,
        entityList: this.approvalrowData
      };
      this.$http
        .approvedFinL(params)
        .then(response1 => {
          let that = this;
          setTimeout(() => {
            loading.close();
            if (response1.data.code == 200) {
              this.$alert("提交成功", {
                    confirmButtonText: "确定",
                    customClass: "alertSuccess"
                });
              that.listArray = [];
              that.$store.dispatch("changeTOdo", { isMyToDoList: 0 });
            } else {
              this.$alert("提交失败："+response1.data.info, {
                  confirmButtonText: "确定",
                  customClass: "alertFailure"
              });
            }
          }, 500);
        })
        .catch(errror => {
          loading.close();
          this.$alert("提交失败，请检查网络！", {
            confirmButtonText: "确定",
            customClass: "alertFailure"
          });
        });
    },
    //退回方法
    sendBack() {
      let _this = this;
      if (this.applyLongForm.backReason == "") {
        this.$alert("请填写退回原因", {
                    confirmButtonText: "确定",
                    customClass: "alertPrompt"
                });
        return;
      }
      this.$confirm("是否确认退回？").then(_ => {
        _this.examinePass = 3;
        _this.applyLongForm.backReason;
        _this.commonUpdate();
      });
    },
    //通过或者退回请求
    commonUpdate() {
      let that = this;
      const loading = this.$loading({
        lock: true,
        text: "处理中，请稍等",
        spinner: "el-icon-loading",
        background: "rgba(255,255,255,.9)"
      });
      let params = {
        name: that.linkName,
        applyId: this.applyId,
        result: this.examinePass,
        note: this.applyLongForm.backReason
      };
      this.$http
        .commonUpdate(params)
        .then(res => {
          setTimeout(() => {
            loading.close();
            if (res.data.code == 200) {
              this.$alert("操作成功！", {
                    confirmButtonText: "确定",
                    customClass: "alertSuccess"
                });
              that.changeTOdo({ isMyToDoList: 0 });
              that.listArray = [];
            } else {
              this.$alert(res.data.info, {
                    confirmButtonText: "确定",
                    customClass: "alertFailure"
                });
            }
          })
        })
        .catch(error => {
          loading.close();
          this.$alert("查询失败，请检查网络！", {
            confirmButtonText: "确定",
            customClass: "alertFailure"
          });
        });
    },

    getApplyInfo() {
      let _this = this;
      var params = {
        id: this.applyId
      };
      this.$http
        .getApplyInfo(params)
        .then(res => {
          setTimeout(() => {
            _this.pageLoading = false;
          }, 500);
          if (res.data.code == 200) {
            let data = res.data.rows;
            this.general = res.data.rows;
            this.general.itemNo = data.itemNo;
            this.general.custName = data.custName;
            this.general.applyUser = data.applyUser;
            this.general.applyPhone = data.applyPhone;
            this.general.custEsignBank = data.custEsignBank;
            this.general.custEsignBankno = data.custEsignBankno;
            this.general.custEsignContact = data.custEsignContact;
            this.general.serviceRate = data.serviceRate;
            this.general.rate = data.rate;
            this.general.applyAmt = data.applyAmt;
            this.general.creditLine = data.creditLine;
            this.general.applyRemark = data.applyRemark;
            this.general.applyDate = data.applyDate.substring(0, 10);
            this.general.prepaybackDate = data.prepaybackDate.substring(0, 10);
            if (this.fromPage != "myToDoList") {
              this.amount = formatPrice(data.actAmt);
              this.beginTime = data.payDate
                ? data.payDate.substring(0, 10)
                : "";
              this.endTime = data.paybackDate
                ? data.paybackDate.substring(0, 10)
                : "";
            }
          } else {
            this.$alert(res.data.info, {
                  confirmButtonText: "确定",
                  customClass: "alertFailure"
              });
          }
        })
        .catch(err => {
          this.loading = false;
          this.pageLoading = false;
          this.$alert("查询数据失败，请检查网络！", {
            confirmButtonText: "确定",
            customClass: "alertFailure"
          });
        });
    },
    //获取实时对账函列表
    getApplyLetterList(params) {
      let that = this;
      that.checkingRowData = [];
      setTimeout(function() {
        that.$http
          .getApplyLetterList(params)
          .then(response => {
            that.checkingLoading = false;
            if (response.data.code == 200) {
              let rowDatas = response.data.rows;
              rowDatas.forEach(element => {
                element.letterNo = element.accountNo; //对账函编号
                element.letterId = element.id; //对账函id
                element.letterMonth = element.month; //对账函月份
              });
              that.checkingRowData = rowDatas;
            } else {
              that.checkingRowData = [];
            }
          })
          .catch(errror => {
            that.$alert("查询对账列表失败，请检查网络！", {
              confirmButtonText: "确定",
              customClass: "alertFailure"
            });
          });
      }, 1000);
    },

    //添加对账函
    addLetter() {
      this.assemblyModel = true;
      let params = {
        supplierId: this.general.custId,
        accountNo: ""
      };
      this.getApplyLetterList(params);
    },
    //搜索对账函
    searchLetter() {
      let params = {
        supplierId: this.general.custId,
        param: this.searchValue
      };
      this.getApplyLetterList(params);
    },
    //删除对账函
    delLetter() {
      let selectRows = this.approvalLongGridOptions.api.getSelectedRows();
      if (selectRows.length == 0) {
        this.$alert("请选择明细进行删除");
        return;
      }
      let originRows = this.approvalrowData;
      this.approvalrowData = this.delSelectRows(selectRows, originRows);
    },
    //删除对账函明细DOM
    delSelectRows(selectArrayData, originArrayData) {
      for (var i = 0; i < selectArrayData.length; i++) {
        originArrayData.splice(originArrayData.indexOf(selectArrayData[i]), 1);
      }
      return originArrayData;
    },
    //对象去重
    unique(objArray) {
      var result = [];
      var temp = {};
      for (var i = 0; i < objArray.length; i++) {
        var myid = objArray[i].id;
        if (temp[myid]) {
          continue;
        }
        temp[myid] = true;
        result.push(objArray[i]);
      }
      return result;
    },

    //保存对账函
    saveLetter() {
      let selectRows = this.checkingGridOptions.api.getSelectedRows();
      if (selectRows <= 0) {
         this.$alert('请选择明细进行保存', {
                  confirmButtonText: "确定",
                  customClass: "alertFailure"
              });
        return;
      }
      this.listArray = this.approvalrowData.concat(selectRows); //数组合并
      this.approvalrowData = this.unique(this.listArray);
      this.checkingRowData = []; //清空弹窗数据
      this.assemblyModel = false;
    },
    //搜索列表
    closeAssemblyModel() {},
    changeAmout() {
      this.amount = formatPriceEdit(this.amount);
    },
    datePickerOptions(time, dateStr, isBeginDate) {
      let weeks = time.getDay(); //周几？
      let day = time.getDate(); //几号？
      // if (isBeginDate && day < 5 || day > 25) {
      //     return false
      // }
      if (this.whitelist.includes(dateStr)) {
        return false;
      }
      if (this.blacklist.includes(dateStr) || weeks == 6 || weeks == 0) {
        return true;
      }
      return false;
    },
    async getDays() {
      let that = this;
      await this.$http
        .getDays()
        .then(({ data }) => {
          if (data.code == 200 && data.rows) {
            that.whitelist = data.rows.workdays;
            that.blacklist = data.rows.holidays;
          } else {
            this.$alert(`获取数据失败：${data.info}`, {
                confirmButtonText: "确定",
                customClass: "alertFailure"
            });
          }
        })
        .catch(error => {
          this.$alert("查询流程图信息失败，请检查网络！", {
            confirmButtonText: "确定",
            customClass: "alertFailure"
          });
        });
    },
    checkNum() {
      if (this.applyAmt) {
        this.applyAmt = regainOriginalMoneyFormat(this.amount);
        const nums = this.amount.toString().split(".");
        if (nums.length == 1) {
          this.amount = this.amount + ".00";
        } else if (nums[1].length == 1) {
          this.amount = this.amount + "0";
        }
        if (this.applyAmt && this.applyAmt < 10000) {
          this.$alert("实际融资金额不得低于一万元", {
                    confirmButtonText: "确定",
                    customClass: "alertPrompt"
                });
          this.amount = "";
          return false;
        }
      }
    },
    //只允许输入两位小数
    clearNoNum() {
      if (typeof this.amount == "string") {
        this.amount = this.amount.replace(/[^(\d|.)]/g, "");
        this.amount = this.amount.replace(/\.{2,}/g, "."); //只保留第一个. 清除多余的
        this.amount = this.amount
          .replace(".", "$#$")
          .replace(/\./g, "")
          .replace("$#$", ".");
        this.amount = this.amount.replace(/^(\-)*(\d+)\.(\d\d).*$/, "$1$2.$3"); //只能输入两个小数
        if (this.amount.indexOf(".") < 0 && this.amount != "") {
          //以上已经过滤，此处控制的是如果没有小数点，首位不能为类似于 01、02的金额
          this.amount = parseFloat(this.amount);
        }
      }
      this.changeAmout();
    }
  },
  components: {},
  computed: {
    //显示利率
    // showRate() {
    //     return formatRate(this.general.rate) + "/天";
    // },
    //获取预扣金额
    getPreDeductAmount() {
      this.general.preDeductAmount = this.general.applyAmt * this.general.rate;
      return this.general.preDeductAmount;
    },
    // getArrivalAmount() {
    //     this.general.arrivalAmount =
    //     this.general.applyAmt -
    //     this.general.applyAmt * this.general.rate;
    //     return formatPrice(this.general.arrivalAmount)
    // },
    getDayAmount() {
        let applyDay = dateDiff(
          this.general.applyDate,
          this.general.prepaybackDate
        );
        if(applyDay > 0){
          applyDay = applyDay - 1
        }
		this.general.dayAmount = applyDay
        return applyDay + "天";
    },
    getDayAmountTab2() {
        let applyDay = dateDiff(this.beginTime, this.endTime);
        if(applyDay > 0){
          applyDay = applyDay - 1
        }
		this.tabDayAmount = applyDay
        return applyDay + "天";
    },
    ...mapState(["supplyChainFinance", "supplierApplyList"]),
    getFormatApplyAmt() {
      return formatPrice(this.general.applyAmt) + " 元";
    },
    getFormatCreditLine() {
      return formatPrice(this.general.creditLine) + " 元";
    },
    // getServiceFee(){
    //     return formatPrice(this.general.applyAmt * this.general.serviceRate)
    // },
    // getInterestFee(){
    //     return formatPrice(this.general.applyAmt * this.general.rate)
    // },
    // getServiceFeeFin(){
    //     return formatPrice(this.amount * this.general.serviceRate)
    // },
    // getInterestFeeFin(){
    //     return formatPrice(this.amount * this.general.rate)
    // },
    //显示利率
    serviceRate() {
      return formatRate(this.general.serviceRate) + "/年";
    },
    //显示利率
    showRate() {
      return formatRate(this.general.rate) + "/年";
    },
    //供应商列表显示
    getNumberRate() {
      let preDeductAmount;
      let numberss = numberMul(
        numberMul(this.general.applyAmt, this.general.rate),
        this.general.dayAmount
      );
      let num;
      if (numberss) {
        num = numberss.toFixed(2);
      }
      preDeductAmount = numberDiv(num, 360);
      return formatPrice(preDeductAmount) + " 元";
    },
    getService() {
      let preDeductAmount;
      let numberss = numberMul(
        numberMul(this.general.applyAmt, this.general.serviceRate),
        this.general.dayAmount
      );
      let num;
      if (numberss) {
        num = numberss.toFixed(2);
      }
      preDeductAmount = numberDiv(num, 360);
      return formatPrice(preDeductAmount) + " 元";
    },
    //金融编辑显示
    getRateFee() {
      let preDeductAmount;
      let amount = regainOriginalMoneyFormat(this.amount);
      let numberss = numberMul(
        numberMul(amount, this.general.rate),
        this.tabDayAmount
      );
      let num;
      if (numberss) {
        num = numberss.toFixed(2);
      }
      preDeductAmount = numberDiv(num, 360);
      return formatPrice(preDeductAmount) + " 元";
    },
    getServiceFee() {
      let preDeductAmount;
      let amount = regainOriginalMoneyFormat(this.amount);
      let numberss = numberMul(
        numberMul(amount, this.general.serviceRate),
        this.tabDayAmount
      );
      let num;
      if (numberss) {
        num = numberss.toFixed(2);
      }
      preDeductAmount = numberDiv(num, 360);
      return formatPrice(preDeductAmount) + " 元";
    },
    pickerOptionsBegin() {
      let dateFormat = this.$utils.dateFormat;
      let prepaybackDate = this.endTime; //取结束日期时间
      //大于当前月25号 的日期不可选
      // let lastDay = getSpecifyDate(25)
      let that = this;
      return {
        disabledDate(time) {
          //开始日期不可大于融资到期日期 并且 开始日期不可大于当前日期
          if (
            (prepaybackDate && time.getTime() > prepaybackDate) ||
            time < new Date()
          ) {
            return true;
          }
          return that.datePickerOptions(
            time,
            dateFormat("yyyy-MM-dd", time),
            true
          );
        }
      };
    },
    pickerOptionsEnd() {
      let dateFormat = this.$utils.dateFormat;
      let beginTime = this.beginTime; //取开始日期时间
      let that = this;
      let date = new Date(beginTime);
      let time1 = date.getTime();
      return {
        disabledDate(time) {
          if (time1 && time1 >= time.getTime()) {
            return true;
          }
          return that.datePickerOptions(time, dateFormat("yyyy-MM-dd", time));
        }
      };
    }
  }
};
</script>
